package com.hilin.entity.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;

import javax.xml.bind.DatatypeConverter;
import java.util.Date;

@Slf4j
@Data
public class EtcdResponseVo {

    private String action;
    private EtcdResponseNodeVo node;

    public static class EtcdResponseNodeVo {
        @Getter
        @Setter
        private String key;
        @Getter
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private Date expiration;
        @Getter
        @Setter
        private Long ttl;
        @Getter
        @Setter
        private long modifiedIndex;
        @Getter
        @Setter
        private long createdIndex;

        public void setExpiration(String expiration) {
            try {
                this.expiration = ObjectUtils.isEmpty(expiration) ?
                        null : DatatypeConverter.parseDateTime(expiration).getTime();
            } catch (Exception e) {
                log.warn("日期转换失败:{}", expiration);
            }
        }
    }

}
